//
//  IntroScreen.m
//  TestFistGame
//
//  Created by  on 5/17/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "IntroScreen.h"
#import "cocos2d.h"
#import "iCoreGUIController.h"

@implementation IntroScreen

-(id)initIntroScreenWith:(iCoreGUIController *)_mainGUIController {
    self = [super initGameLayerWith:_mainGUIController];
    mainGUIController = _mainGUIController;
    
    [self loadResource];
    
    return self;
}

-(void)loadResource {
    fadeSprite = [[CCSprite alloc]initWithFile:BLANK_IMAGE];
    fadeSprite.opacity = 0;
    fadeSprite.position = ccp(240, 160);
    fadeSprite.textureRect = CGRectMake(0, 0, 480, 360);
    [self addChild:fadeSprite z:3];
    
    logoSprite = [[CCSprite alloc]initWithFile:INTRO_LOGO_IMAGE];
    logoSprite.position = ccp(0, 0);
    logoSprite.anchorPoint = ccp(0, 0);
    [self addChild:logoSprite z:0];  
    
    [self performSelector:@selector(startFadeAnimation:) withObject:nil afterDelay:2.5];
}

-(void)startFadeAnimation:(id)_sender {
	[fadeSprite stopAllActions];
	[fadeSprite setColor:ccc3(255,255,255)];
	[fadeSprite setOpacity:0.0f];
	
    CCCallFunc *removeScreenAction = [CCCallFunc actionWithTarget:self selector:@selector(removeLogo)];
    CCCallFunc *endScreenAction = [CCCallFunc actionWithTarget:self selector:@selector(endScreen)];
    
    [fadeSprite runAction: [CCSequence actions:[CCFadeIn actionWithDuration:1.5f], removeScreenAction, [CCFadeOut actionWithDuration:1.5f], endScreenAction, nil] ];
}

-(void)removeLogo {
    logoSprite.visible = NO;
}

-(void)endScreen {
    [self stopAllActions];
    [mainGUIController runGameScreen:GAME_SCREEN_MAIN_MENU];
}

-(void)dealloc {
    NSLog(@"dealloc is called");
    [fadeSprite release];    
    [logoSprite release];
    [super dealloc];
}

@end
